/**
 * 详情对话框
 */
var DemandInfoDlg = {
    data: {
        code: "",
        name: "",
        status: "",
        deleteStatus: "",
        productId: "",
        featureId: "",
        createUser: "",
        createTime: "",
        lastMidifiedUser: "",
        lastModifiedTime: ""
    }
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/demand/editItem", function (data) {
            Feng.success("更新成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    var ajax = new $ax(Feng.ctxPath + "/product/listAll", function (data) {
        var str = '<option value="">请选择产品ID</option>';
        for (var i = 0; i < data.length; i++) {
            str += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
        }
        $('#productId').html(str);
        form.render('select')
    }, function (data) {
    });
    ajax.start();

    form.on('select(productId)', function (data) {
        console.log(data.elem); //得到select原始DOM对象
        console.log(data.value); //得到被选中的值
        console.log(data.othis); //得到美化后的DOM对象

        var ajax2 = new $ax(Feng.ctxPath + "/feature/listAll?productId=" + data.value, function (data) {
            var str = '<option value="">请选择功能</option>';
            for (var i = 0; i < data.length; i++) {
                str += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
            }
            $('#featureId').html(str);
            form.render('select')
        }, function (data) {
        });
        ajax2.start();
    });


    //获取详情信息，填充表单
    var ajaxt = new $ax(Feng.ctxPath + "/demand/detail?id=" + Feng.getUrlParam("id"));
    var result = ajaxt.start();
    form.val('demandForm', result.data);
    var ajax2 = new $ax(Feng.ctxPath + "/feature/listAll?productId=" + $("#productId").val(), function (data) {
        var str = '<option value="">请选择功能</option>';
        for (var i = 0; i < data.length; i++) {
            str += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
        }
        $('#featureId').html(str);
        form.render('select')
        form.val('demandForm', result.data);
    }, function (data) {
    });
    ajax2.start()
});